@extends('admin.layouts.content')
@section('content')

    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">上级功能</label>
            <div class="layui-input-block">
                <select name="pid" lay-verify="required" class="layui-input">
                    @foreach($selectOptions as $optionKey => $optionValue)
                        @if($model->pid == $optionKey)
                            <option value="{{$optionKey}}" selected="selected">{!! $optionValue !!}</option>
                        @else
                            <option value="{{$optionKey}}">{!! $optionValue !!}</option>
                        @endif
                    @endforeach
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">功能名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="{{$model->name}}"
                       lay-verify="required" placeholder="请输入菜单名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">功能路径</label>
            <div class="layui-input-block">
                <input type="text" name="route" value="{{$model->route}}" laceholder="请输入功能路径" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示图标</label>
            <div class="layui-input-block">
                <input type="text" name="icon"
                       value="{{ $model->icon }}"
                       placeholder="请输入显示图标" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">功能类型</label>
            <div class="layui-input-block">
                <select name="is_menu" class="layui-input">
                    <option value="1" @if($model->is_menu == 1) selected="selected" @endif>菜单</option>
                    <option value="0" @if($model->is_menu == 0) selected="selected" @endif>功能</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="is_disabled" class="layui-input">
                    <option value="1" @if($model->is_disabled == 1) selected="selected" @endif>禁用</option>
                    <option value="0" @if($model->is_disabled == 0) selected="selected" @endif>启用</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" value="{{ $model->sort }}" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
        </div>
    </div>

@endsection
@section('script')
<script>
    layui.use(['jquery', 'form'], function(){
        var $ = layui.$ ,form = layui.form;
        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: "{{url('admin/menu/update')}}/{{$model->id}}",
                method: "POST",
                dataType : "json",
                data: data.field,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function (json) {
                    parent.layui.table.reload('LAY-app-content-list'); //重载表格
                    parent.layer.close(index); //再执行关闭
                },
                error: function () {
                    layer.msg('系统错误');
                }
            });

        });
    })
</script>
@endsection
